﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;
public partial class Search_Safty_View : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] != null)
        {
            string id = Request["id"];
            Query q = new Query(CxApply.Schema);
            q.AddWhere("id", id);
            q.AddWhere("uid", Cookies.getCookies("cuid"));

            q.SetSelectList("bossnod,dateadd(day,15,bosstime),guid");
            if (q.GetRecordCount() == 0)
            {
                Err.Warning("没有该条记录！", MessageBox.Icon.ERROR);
                return;
            }

                IDataReader dr = q.ExecuteReader();
                if (dr.Read())
                {
                    if (dr["bossnod"].ToString() == "0")
                    {
                        Err.Warning("请等待审核！", MessageBox.Icon.WARNING);
                        return;
                    }
                    if (dr["bossnod"].ToString() != "1")
                    {
                        Err.Warning("您的申请已被管理员拒绝，请重新申请！", MessageBox.Icon.WARNING);
                        return;
                    }
                    if (DateTime.Parse(dr[1].ToString()) <= DateTime.Now)
                    {
                        Err.Warning("您的申请已过期，请重新申请！", MessageBox.Icon.WARNING);
                        return;
                    }
                    //开始输出数据
                    Query query = new Query(VwStaffSaftyStep1.Schema);
                    query.AddWhere("guid", dr["guid"].ToString());
                    IDataReader r = query.ExecuteReader();
                    if (r.Read())
                    {
                        tfaccident_time.Text = r["accident_time"].ToString();
                        tfaccident_duty.Text = r["accident_duty"].ToString();
                        tfaccident_reason.Text = r["accident_reason"].ToString();
                        tfsafty_masterid.Text = Username(r["safty_masterid"].ToString());
                        tfsafty_master_time.Text = r["safty_master_time"].ToString();
                        tfsafty_master_status.Text = Status(r["safty_master_status"].ToString());
                        tfsafty_master_remark.Text = r["safty_master_remark"].ToString();
                        tfdept_master_id.Text = Username(r["dept_master_id"].ToString());
                        tfdept_master_time.Text = r["dept_master_time"].ToString();
                        tfdept_master_status.Text = Status(r["dept_master_status"].ToString());
                        tfdept_master_remark.Text = r["dept_master_remark"].ToString();
                        tfboss_userid.Text = Username(r["boss_userid"].ToString());
                        tfboss_time.Text = r["boss_time"].ToString();
                        tfboss_status.Text = Status(r["boss_status"].ToString());
                        tfboss_remark.Text = r["boss_remark"].ToString();
                        tfen_username.Text = r["en_username"].ToString();
                        tfen_deptname.Text = r["en_deptname"].ToString();
                        tfintime.Text = r["intime"].ToString();
                        tfed_username.Text = dr["ed_username"].ToString();
                        string[] str = CXFileUpload.show(new Guid(dr["guid"].ToString())).Split('$');
                        tfzip.Text = str[1];
                        tfzip.NavigateUrl = str[0];
                    }
                }
             
        }
    }
    protected string Username(string uid)
    {
        if (uid == "")
        {
            return "未指定";
        }
        Query q = new Query(CxUserBase.Schema);
        q.AddWhere("uid", uid);
        q.SetSelectList("username");
        return q.ExecuteScalar().ToString();
    }
    protected string Status(string s)
    {
        switch (s)
        {
            case "0":
                return "未审核";
                break;
            case "1":
                return "同意";
                break;
            case "2":
                return "退回";
                break;
            default:
                break;
        }
        return "未知";
    }
}
